﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommerceForUmbraco.usercontrols.usercontrols.commerce
{
    public partial class PWForceSSLorNoSSL : System.Web.UI.UserControl
    {
        public string ForceSSL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsoluteUri;
            if (Request.Url.Scheme == "https" && ForceSSL != "1")
            {
                UriBuilder build = new UriBuilder(Request.Url);
                build.Scheme = "http";
                build.Port = -1;  // don't inject port

                Uri newUri = build.Uri;
                string newUrl = build.ToString();

                Response.Redirect(newUrl);
            }
            else if (Request.Url.Scheme == "http" && ForceSSL == "1")
            {
                UriBuilder build = new UriBuilder(Request.Url);
                build.Scheme = "https";
                build.Port = -1;  // don't inject port

                Uri newUri = build.Uri;
                string newUrl = build.ToString();

                Response.Redirect(newUrl);
            }
        }
    }
}